/**
 * Created by alan on 2017/5/5.
 * 角色管理
 */

Ext.define('Admin.view.sys.role', {
	extend: "Admin.common.container.BaseContainer",
	xtype: 'role',
	//起别名
	alias: 'role',
	requires: [
		'Admin.store.sys.Role'
	],
	controller: 'roleController',
	userCLs: 'big-100 small-100',
	layout: 'fit',
	width: '100%',
	height: 200,

	items: [
		{
			title: '角色管理',
			xtype: 'grid',
			border:true,
			tbar: [{
					xtype: "textfield",
					maxWidth: 220,
					fieldLabel: "名称",
					labelWidth: 30,
					reference: "name"
				},
				{
					xtype: "button",
					text: "查询",
					iconCls: 'x-fa fa-search',
					handler: 'check',
					margin: '0 10 0 10',
					// style: 'background-color:#108ee9; border-radius:4px;-webkit-border-radius: 4px;',
					style: 'border-radius:4px;-webkit-border-radius: 4px;'
				},
				{
					xtype: "button",
					text: "新增",
					iconCls: 'x-fa fa-save',
					handler: 'addrole',
					margin: '0 10 0 10',
					// style: 'background-color:#108ee9; border-radius:4px;-webkit-border-radius: 4px;',
					style: 'border-radius:4px;-webkit-border-radius: 4px;'
				}
			],
			reference: 'roleGrid',
			columns: [{
					header: '角色ID',
					dataIndex: 'id',
					/** editor: 'textfield' ,*/
					align: 'center',
					hidden: true
				},
				{
					header: '角色名称',
					dataIndex: 'name',
					/** editor: 'textfield' ,*/
					align: 'center',
					flex: 1
				},
				{
					header: '英文名称',
					dataIndex: 'enname',
					/** editor: 'textfield' ,*/
					align: 'center',
					flex: 1
				},
				// {header: '归属机构', dataIndex: 'enname', /** editor: 'textfield' ,*/align:'center',width:'20%'},
				// {header: '数据范围', dataIndex: 'dataScope',/** editor: 'textfield' ,*/align:'center',width:'20%'},
				{
					header: '操作',
					dataIndex: 'operate',
					/** editor: 'textfield' ,*/
					align: 'center',
					xtype: 'actioncolumn',
					width: 100,
					items: [{
						xtype: 'button',
						text: '修改',
						iconCls: "x-fa fa-edit",
						style: 'border-radius:4px;-webkit-border-radius: 4px;',
						handler: 'update'
					}, {
						xtype: 'button',
						text: '删除',
						iconCls: "x-fa fa-trash",
						style: 'border-radius:4px;-webkit-border-radius: 4px;',
						handler: 'delete'
					}]
				}

			],
			store: {
				type: 'role'
			},
			bbar: [{
				xtype: "pagingtoolbar",
				store: {
					type: 'role'
				},
				autoLoad: true,
				displayInfo: true,
				displayMsg: "显示从第{0}条数据到第{1}条数据，共{2}条数据",
				emptyMsg: "没有记录"
			}],
			stripeRows: true,
			columnLines: true,
			plugins: {
				ptype: 'cellediting',
				clicksToEdit: 1
			}
		}
	]
});

Ext.define("NodeStore", {
	extend: 'Ext.data.TreeStore',
	proxy: {
		type: 'ajax',
		url: config.URL + 'szy/sys/menu/treeData?extId=0',
		reader: 'json',
		autoLoad: true
	},
	fields: [{
		name: 'id',
		type: 'string'
	}, {
		name: 'text',
		type: 'string'
	}, {
		name: 'iconCls',
		type: 'string'
	}]
});
var selModel = Ext.create('Ext.selection.CheckboxModel');
Ext.define("Admin.view.sys.roleWindowForm", {
	// extend: 'Ext.form.Panel',
	extend: "Admin.common.form.BaseFormPanel",
	xtype: "roleWindowForm",
	alias: "roleWindowForm",
	requires: [
		"Ext.panel.Panel",
		"Ext.grid.Panel",
		"Ext.button.Button",
		'Ext.ux.CheckColumn',
	],
	bodyPadding: 10,
	layout: "anchor",
	defaults: {
		anchor: "100%",
		labelWidth: 60,
		labelAlign: "right"
	},
	items: [{
			xtype: "textfield",
			name: "id",
			fieldLabel: "角色ID",
			// allowBlank: false,
			anchor: "100%",
			hidden: true
		},
		{
			xtype: "textfield",
			name: "name",
			fieldLabel: "角色名称",
			allowBlank: false,
			anchor: "100%"
		},
		{
			xtype: "textfield",
			name: "enname",
			fieldLabel: "英文名称",
			anchor: "100%",
			// hidden: true,
		},
		// Ext.create("Ext.tree.Panel", {
		// 	// title: "角色权限菜单",
		// 	columnLines: true,
		// 	height: 400,
		// 	border:true,
		// 	scrollable:true,
		// 	// reference: 'checkboxtree',
		// 	root: {
		// 		name: '根目录',
		// 		expanded: true,
		// 	},
		// 	columns: [
		// 		{
		// 			xtype: 'checkcolumn',
		// 			header: '多选',
		// 			dataIndex: 'done',
		// 			width:60,
		// 			stopSelection: false,
		// 		},
		// 		{ xtype: 'treecolumn', text: '菜单名称', dataIndex: 'text', align: 'left', flex:1 },
		// 		{ text: 'Id', dataIndex: 'id', hidden: true },
		// 	],

		// 	loadMask: {
		// 		msg: '正在加载数据,请稍等...'
		// 	},
		// 	store: Ext.create('NodeStore'),
		// }),
		{
			xtype: 'panel',
			layout: 'hbox',
			items: [{
				xtype: 'panel',
				width: 65,
				bodyPadding: '0 5 0 0',
				align: 'right',
				html: '<div style="text-align:right">角色权限:</div>'
			}, {
				xtype: 'panel',
				flex: 1,
				items: Ext.create("Ext.tree.Panel", {
					// title: "角色权限菜单",
					columnLines: true,
					height: 400,
					border: true,
					scrollable: true,
					// reference: 'checkboxtree',
					root: {
						name: '根目录',
						expanded: true,
					},
					columns: [{
							xtype: 'checkcolumn',
							header: '多选',
							dataIndex: 'done',
							width: 60,
							stopSelection: false,
						},
						{
							xtype: 'treecolumn',
							text: '菜单名称',
							dataIndex: 'text',
							align: 'left',
							flex: 1
						},
						{
							text: 'Id',
							dataIndex: 'id',
							hidden: true
						},
					],

					loadMask: {
						msg: '正在加载数据,请稍等...'
					},
					store: Ext.create('NodeStore'),
				})
			}]
		}

	]
});